package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.ArtRec;
import com.ruoyi.system.model.domain.GameAttrTemplate;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.goods.NEWLXYCAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/8/16 22:58
 */
@Slf4j
@Service
public class NEWLXYCApiImpl implements NEWLXYCAPI {

    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    InterAttrMapper interAttrMapper;

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        TreeMap<String, Object> resultMap = new TreeMap<>();

        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, 1);
        log.info("云仓添加接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpUtils.doPostForm("https://www.cyjh.co/api/v1/external-share-yc/goods-receive", params, null);
        log.info("云仓添加接口返回参数={}", result);
        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("code"))){
            resultMap.put("code",500);
            if(resultJson.getString("msg").contains("商品上传失败:该商品已存在，请不要重复添加")){
                //调上架
                Map<String, Object> params2 = params(goodsInfoAndAttrValueDto, salePartner, 4);

                log.info("云仓删除接口请求参数={}", JSONObject.toJSONString(params2));
                String results = HttpUtils.doPostForm("https://www.cyjh.co/api/v1/external-share-yc/goods-receive", params2, null);
                JSONObject resultJson2 = JSONObject.parseObject(results);
                if (!"200".equals(resultJson2.getString("code"))){
                    resultMap.put("code",500);
                    resultMap.put("req",JSONObject.toJSONString(params));
                    resultMap.put("res",result);
                    resultMap.put("msg",resultJson.getString("data"));
                    return AjaxResult.success(resultMap);
                }else {
                    String data = resultJson2.getString("data");
                    String goodsSn = JSONObject.parseObject(data).getString("goodsSn");
                    ArtRec artRecreq = new ArtRec();
                    artRecreq.setConfig(salePartner.getId());
                    artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
                    List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
                    if (CollectionUtils.isNotEmpty(artRecs)) {
                        artRecs.get(0).setOutid(goodsSn);
                        artRecMapper.updateArtRec(artRecs.get(0));
                    } else {
                        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
                        artRecreq.setCreateId(goodsInfoAndAttrValueDto.getCreateId());
                        artRecreq.setType(LCConstant.interAdd);
                        artRecreq.setConfig(salePartner.getId());
                        artRecreq.setSaleCode(salePartner.getSaleName());
                        artRecreq.setOutid(goodsSn);
                        artRecMapper.insertArtRec(artRecreq);
                    }
                    resultMap.put("code",200);
                    resultMap.put("req",JSONObject.toJSONString(params));
                    resultMap.put("res",result);
                    resultMap.put("msg",resultJson.getString("data"));
                    return AjaxResult.success(resultMap);
                }
            }
        }else {
            resultMap.put("code",200);
            String data = resultJson.getString("data");
            JSONObject.parseObject(data).getString("");
            resultMap.put("outId", data);
        }
        resultMap.put("req",JSONObject.toJSONString(params));
        resultMap.put("res",result);
        resultMap.put("msg",resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto , SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();

        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, 2);
        log.info("云仓编辑接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpUtils.doPostForm("https://www.cyjh.co/api/v1/external-share-yc/goods-receive", params, null);
        log.info("云仓编辑接口返回参数={}", result);


        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("code"))){
            resultMap.put("code",500);
        }else {
            resultMap.put("code",200);
        }
        resultMap.put("req",JSONObject.toJSONString(params));
        resultMap.put("res",result);
        resultMap.put("msg",resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();
        TreeMap<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, 3);
        log.info("云仓删除接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpUtils.doPostForm("https://www.cyjh.co/api/v1/external-share-yc/goods-receive", params, null);
        log.info("云仓删除接口返回参数={}", result);
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("code"))){
            resultMap.put("code",500);
        }else {
            resultMap.put("code",200);
        }
        resultMap.put("req",JSONObject.toJSONString(params));
        resultMap.put("res",result);
        resultMap.put("msg",resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    private TreeMap<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner, Integer type) {
        TreeMap<String, Object> params = new TreeMap<>();
        TreeMap<String, Object> upperConf = new TreeMap<>();
        TreeMap<String, Object> duoxuanmap = new TreeMap<>();

        params.put("merchantId", Integer.parseInt(salePartner.getOther()));
        if(type==4){
            params.put("operation", 3);
        }else {
            params.put("operation", type);
        }
        if(type!=3) {
            params.put("title", goodsInfoAndAttrValueDto.getDes().replace("+",""));
        }
        params.put("outSn", String.valueOf(goodsInfoAndAttrValueDto.getId()));

        goodsInfoAndAttrValueDto.setDes(goodsInfoAndAttrValueDto.getDes().replace("+",""));
        List<Map<String, Object>> urlArr = goodsInfoAndAttrValueDto.getUrlArr();
        StringBuffer imgs = new StringBuffer();
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getTitleImg())){
            imgs.append(goodsInfoAndAttrValueDto.getTitleImg()+",");
        }
        for(Map<String, Object> maps : urlArr){
            String ss = String.valueOf(maps.get("url"));
            String imgStr = ss + ",";
            imgs.append(imgStr);
        }
        String imgUrls = imgs.toString().substring(0, imgs.length() - 1);
        upperConf.put("shangpinxiangqingtu", imgUrls);
        upperConf.put("shangpinmiaoshu", goodsInfoAndAttrValueDto.getDes());
        upperConf.put("shangpinfengmiantu", goodsInfoAndAttrValueDto.getTitleImg());
        //属性匹配
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring,goodsInfoAndAttrValueDto.getGameId());
        if(type==1) {
            params.put("gameId", Integer.parseInt(interAttr.getInterGameId()));
            params.put("goodsTypeId", 1);
        }

        if(goodsInfoAndAttrValueDto.getGameName().equals("三角洲行动")){
            duoxuanmap.put("ids","43294");
            duoxuanmap.put("names","WeGame");
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("使命召唤手游")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","39920,39929");
                duoxuanmap.put("names","苹果微信,微信服务器");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","39918,39923");
                duoxuanmap.put("names","安卓微信,微信服务器");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","39919,39925");
                duoxuanmap.put("names","苹果QQ,QQ服务器");
            }else {
                duoxuanmap.put("ids","39917,39921");
                duoxuanmap.put("names","安卓QQ,QQ服务器");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("暗区突围")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","44758");
                duoxuanmap.put("names","苹果微信");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","44756");
                duoxuanmap.put("names","安卓微信");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","44757");
                duoxuanmap.put("names","苹果QQ");
            }else {
                duoxuanmap.put("ids","44755");
                duoxuanmap.put("names","安卓QQ");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","8853,9157");
                duoxuanmap.put("names","苹果微信,全服通用");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","8854,9458");
                duoxuanmap.put("names","安卓微信,全服通用");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","8855,9759");
                duoxuanmap.put("names","苹果QQ,全服通用");
            }else {
                duoxuanmap.put("ids","8856,10060");
                duoxuanmap.put("names","安卓QQ,全服通用");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("和平精英")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","2067");
                duoxuanmap.put("names","苹果微信");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","2070");
                duoxuanmap.put("names","安卓微信");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","2068");
                duoxuanmap.put("names","苹果QQ");
            }else {
                duoxuanmap.put("ids","2069");
                duoxuanmap.put("names","安卓QQ");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("原神")){
            if(goodsInfoAndAttrValueDto.getCarrierName().equals("游戏官方")) {
                duoxuanmap.put("ids","1581");
                duoxuanmap.put("names","官服（天空岛服）");
            }else {
                duoxuanmap.put("ids","1582");
                duoxuanmap.put("names","B服（世界树服）");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟")){
            String qufus = "[{\"id\":10382,\"parentFilterConfId\":0,\"name\":\"电信区\",\"sort\":0,\"children\":[{\"id\":10386,\"parentFilterConfId\":10382,\"name\":\"影流\",\"sort\":0,\"children\":[]},{\"id\":10387,\"parentFilterConfId\":10382,\"name\":\"皮城警备\",\"sort\":0,\"children\":[]},{\"id\":10388,\"parentFilterConfId\":10382,\"name\":\"卡拉曼达\",\"sort\":0,\"children\":[]},{\"id\":10389,\"parentFilterConfId\":10382,\"name\":\"征服之海\",\"sort\":0,\"children\":[]},{\"id\":10390,\"parentFilterConfId\":10382,\"name\":\"守望之海\",\"sort\":0,\"children\":[]},{\"id\":10391,\"parentFilterConfId\":10382,\"name\":\"艾欧尼亚\",\"sort\":0,\"children\":[]},{\"id\":10392,\"parentFilterConfId\":10382,\"name\":\"均衡教派\",\"sort\":0,\"children\":[]},{\"id\":10393,\"parentFilterConfId\":10382,\"name\":\"水晶之痕\",\"sort\":0,\"children\":[]},{\"id\":10394,\"parentFilterConfId\":10382,\"name\":\"雷瑟守备\",\"sort\":0,\"children\":[]},{\"id\":10395,\"parentFilterConfId\":10382,\"name\":\"巨神峰\",\"sort\":0,\"children\":[]},{\"id\":10396,\"parentFilterConfId\":10382,\"name\":\"战争学院\",\"sort\":0,\"children\":[]},{\"id\":10397,\"parentFilterConfId\":10382,\"name\":\"皮尔特沃夫\",\"sort\":0,\"children\":[]},{\"id\":10398,\"parentFilterConfId\":10382,\"name\":\"诺克萨斯\",\"sort\":0,\"children\":[]},{\"id\":10399,\"parentFilterConfId\":10382,\"name\":\"祖安\",\"sort\":0,\"children\":[]},{\"id\":10400,\"parentFilterConfId\":10382,\"name\":\"黑色玫瑰\",\"sort\":0,\"children\":[]},{\"id\":10401,\"parentFilterConfId\":10382,\"name\":\"钢铁烈阳\",\"sort\":0,\"children\":[]},{\"id\":10402,\"parentFilterConfId\":10382,\"name\":\"裁决之地\",\"sort\":0,\"children\":[]},{\"id\":10403,\"parentFilterConfId\":10382,\"name\":\"班德尔城\",\"sort\":0,\"children\":[]},{\"id\":10404,\"parentFilterConfId\":10382,\"name\":\"暗影岛\",\"sort\":0,\"children\":[]}]},{\"id\":10383,\"parentFilterConfId\":0,\"name\":\"网通区\",\"sort\":0,\"children\":[{\"id\":10405,\"parentFilterConfId\":10383,\"name\":\"巨龙之巢\",\"sort\":0,\"children\":[]},{\"id\":10406,\"parentFilterConfId\":10383,\"name\":\"扭曲丛林\",\"sort\":0,\"children\":[]},{\"id\":10407,\"parentFilterConfId\":10383,\"name\":\"恕瑞玛\",\"sort\":0,\"children\":[]},{\"id\":10408,\"parentFilterConfId\":10383,\"name\":\"无畏先锋\",\"sort\":0,\"children\":[]},{\"id\":10409,\"parentFilterConfId\":10383,\"name\":\"弗雷尔卓德\",\"sort\":0,\"children\":[]},{\"id\":10410,\"parentFilterConfId\":10383,\"name\":\"德玛西亚\",\"sort\":0,\"children\":[]},{\"id\":10411,\"parentFilterConfId\":10383,\"name\":\"比尔吉沃特\",\"sort\":0,\"children\":[]}]},{\"id\":10384,\"parentFilterConfId\":0,\"name\":\"其他\",\"sort\":0,\"children\":[{\"id\":10412,\"parentFilterConfId\":10384,\"name\":\"教育网专区\",\"sort\":0,\"children\":[]}]},{\"id\":10385,\"parentFilterConfId\":0,\"name\":\"全网络大区\",\"sort\":0,\"children\":[{\"id\":10413,\"parentFilterConfId\":10385,\"name\":\"峡谷之巅\",\"sort\":0,\"children\":[]},{\"id\":10414,\"parentFilterConfId\":10385,\"name\":\"男爵领域\",\"sort\":0,\"children\":[]}]}]\n";
            JSONArray jsonArray1 = JSONArray.parseArray(qufus);
            String ids = "";
            String names = "";
            for(Object o : jsonArray1){
                String children = JSONObject.parseObject(o.toString()).getString("children");
                JSONArray jsonArray2 = JSONArray.parseArray(children);
                for(Object p : jsonArray2){
                    if(goodsInfoAndAttrValueDto.getServerName().contains(JSONObject.parseObject(p.toString()).getString("name"))){
                        duoxuanmap.put("ids",JSONObject.parseObject(o.toString()).getString("id"));
                        duoxuanmap.put("names",JSONObject.parseObject(o.toString()).getString("name"));
                        ids+=JSONObject.parseObject(o.toString()).getString("id");
                        ids+=","+JSONObject.parseObject(p.toString()).getString("id");
                        names+=JSONObject.parseObject(o.toString()).getString("name");
                        names+=","+JSONObject.parseObject(p.toString()).getString("name");
                    }
                }
            }
            duoxuanmap.put("ids",ids);
            duoxuanmap.put("names",names);
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("穿越火线")){
            String qufus = "[{\"id\":8614,\"parentFilterConfId\":0,\"name\":\"电信区\",\"sort\":0,\"children\":[{\"id\":8618,\"parentFilterConfId\":8614,\"name\":\"浙江二区\",\"sort\":0,\"children\":[]},{\"id\":8619,\"parentFilterConfId\":8614,\"name\":\"重庆一区\",\"sort\":0,\"children\":[]},{\"id\":8620,\"parentFilterConfId\":8614,\"name\":\"浙江一区\",\"sort\":0,\"children\":[]},{\"id\":8621,\"parentFilterConfId\":8614,\"name\":\"江苏一区\",\"sort\":0,\"children\":[]},{\"id\":8622,\"parentFilterConfId\":8614,\"name\":\"福建一区\",\"sort\":0,\"children\":[]},{\"id\":8623,\"parentFilterConfId\":8614,\"name\":\"广东一区\",\"sort\":0,\"children\":[]},{\"id\":8624,\"parentFilterConfId\":8614,\"name\":\"广东二区\",\"sort\":0,\"children\":[]},{\"id\":8625,\"parentFilterConfId\":8614,\"name\":\"广东三区\",\"sort\":0,\"children\":[]},{\"id\":8626,\"parentFilterConfId\":8614,\"name\":\"广东四区\",\"sort\":0,\"children\":[]},{\"id\":8627,\"parentFilterConfId\":8614,\"name\":\"广西一区\",\"sort\":0,\"children\":[]},{\"id\":8628,\"parentFilterConfId\":8614,\"name\":\"湖北一区\",\"sort\":0,\"children\":[]},{\"id\":8629,\"parentFilterConfId\":8614,\"name\":\"湖北二区\",\"sort\":0,\"children\":[]},{\"id\":8630,\"parentFilterConfId\":8614,\"name\":\"湖南一区\",\"sort\":0,\"children\":[]},{\"id\":8631,\"parentFilterConfId\":8614,\"name\":\"湖南二区\",\"sort\":0,\"children\":[]},{\"id\":8632,\"parentFilterConfId\":8614,\"name\":\"安徽一区\",\"sort\":0,\"children\":[]},{\"id\":8633,\"parentFilterConfId\":8614,\"name\":\"江苏二区\",\"sort\":0,\"children\":[]},{\"id\":8634,\"parentFilterConfId\":8614,\"name\":\"江西一区\",\"sort\":0,\"children\":[]},{\"id\":8635,\"parentFilterConfId\":8614,\"name\":\"南方大区\",\"sort\":0,\"children\":[]},{\"id\":8636,\"parentFilterConfId\":8614,\"name\":\"陕西一区\",\"sort\":0,\"children\":[]},{\"id\":8637,\"parentFilterConfId\":8614,\"name\":\"上海一区\",\"sort\":0,\"children\":[]},{\"id\":8638,\"parentFilterConfId\":8614,\"name\":\"上海二区\",\"sort\":0,\"children\":[]},{\"id\":8639,\"parentFilterConfId\":8614,\"name\":\"四川一区\",\"sort\":0,\"children\":[]},{\"id\":8640,\"parentFilterConfId\":8614,\"name\":\"四川二区\",\"sort\":0,\"children\":[]},{\"id\":8641,\"parentFilterConfId\":8614,\"name\":\"云南一区\",\"sort\":0,\"children\":[]}]},{\"id\":8615,\"parentFilterConfId\":0,\"name\":\"网通区\",\"sort\":0,\"children\":[{\"id\":8642,\"parentFilterConfId\":8615,\"name\":\"黑龙江区\",\"sort\":0,\"children\":[]},{\"id\":8643,\"parentFilterConfId\":8615,\"name\":\"北方大区\",\"sort\":0,\"children\":[]},{\"id\":8644,\"parentFilterConfId\":8615,\"name\":\"北京一区\",\"sort\":0,\"children\":[]},{\"id\":8645,\"parentFilterConfId\":8615,\"name\":\"北京二区\",\"sort\":0,\"children\":[]},{\"id\":8646,\"parentFilterConfId\":8615,\"name\":\"北京三区\",\"sort\":0,\"children\":[]},{\"id\":8647,\"parentFilterConfId\":8615,\"name\":\"北京四区\",\"sort\":0,\"children\":[]},{\"id\":8648,\"parentFilterConfId\":8615,\"name\":\"河北一区\",\"sort\":0,\"children\":[]},{\"id\":8649,\"parentFilterConfId\":8615,\"name\":\"河南一区\",\"sort\":0,\"children\":[]},{\"id\":8650,\"parentFilterConfId\":8615,\"name\":\"河南二区\",\"sort\":0,\"children\":[]},{\"id\":8651,\"parentFilterConfId\":8615,\"name\":\"吉林一区\",\"sort\":0,\"children\":[]},{\"id\":8652,\"parentFilterConfId\":8615,\"name\":\"辽宁一区\",\"sort\":0,\"children\":[]},{\"id\":8653,\"parentFilterConfId\":8615,\"name\":\"辽宁二区\",\"sort\":0,\"children\":[]},{\"id\":8654,\"parentFilterConfId\":8615,\"name\":\"辽宁三区\",\"sort\":0,\"children\":[]},{\"id\":8655,\"parentFilterConfId\":8615,\"name\":\"山东一区\",\"sort\":0,\"children\":[]},{\"id\":8656,\"parentFilterConfId\":8615,\"name\":\"山东二区\",\"sort\":0,\"children\":[]},{\"id\":8657,\"parentFilterConfId\":8615,\"name\":\"山西一区\",\"sort\":0,\"children\":[]}]},{\"id\":8616,\"parentFilterConfId\":0,\"name\":\"体验区\",\"sort\":0,\"children\":[{\"id\":8658,\"parentFilterConfId\":8616,\"name\":\"高清竞技大区\",\"sort\":0,\"children\":[]}]},{\"id\":8617,\"parentFilterConfId\":0,\"name\":\"其他大区\",\"sort\":0,\"children\":[{\"id\":8659,\"parentFilterConfId\":8617,\"name\":\"教育网专区\",\"sort\":0,\"children\":[]},{\"id\":8660,\"parentFilterConfId\":8617,\"name\":\"移动专区\",\"sort\":0,\"children\":[]}]}]\n";
            JSONArray jsonArray1 = JSONArray.parseArray(qufus);
            for(Object o : jsonArray1){
                String children = JSONObject.parseObject(o.toString()).getString("children");
                JSONArray jsonArray2 = JSONArray.parseArray(children);
                for(Object p : jsonArray2){
                    if(goodsInfoAndAttrValueDto.getServerName().contains(JSONObject.parseObject(p.toString()).getString("name"))){
                        duoxuanmap.put("ids",JSONObject.parseObject(p.toString()).getString("id"));
                        duoxuanmap.put("names",JSONObject.parseObject(p.toString()).getString("name"));
                    }
                }
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("枪战王者")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","34695");
                duoxuanmap.put("names","苹果微信");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","34694");
                duoxuanmap.put("names","安卓微信");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","34693");
                duoxuanmap.put("names","苹果QQ");
            }else {
                duoxuanmap.put("ids","34692");
                duoxuanmap.put("names","安卓QQ");
            }
            upperConf.put("caozuoxitong", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("火影忍者")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","2602");
                duoxuanmap.put("names","苹果微信");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","2603");
                duoxuanmap.put("names","安卓微信");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","2604");
                duoxuanmap.put("names","苹果QQ");
            }else {
                duoxuanmap.put("ids","2605");
                duoxuanmap.put("names","安卓QQ");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("光遇")){
            String qufus = "[{\"id\":11839,\"parentFilterConfId\":0,\"name\":\"安卓\",\"sort\":0,\"children\":[{\"id\":11841,\"parentFilterConfId\":11839,\"name\":\"网易手机\",\"sort\":0,\"children\":[]},{\"id\":11842,\"parentFilterConfId\":11839,\"name\":\"网易邮箱\",\"sort\":0,\"children\":[]},{\"id\":11843,\"parentFilterConfId\":11839,\"name\":\"OPPO安卓\",\"sort\":0,\"children\":[]},{\"id\":11844,\"parentFilterConfId\":11839,\"name\":\"网易安卓\",\"sort\":0,\"children\":[]},{\"id\":11845,\"parentFilterConfId\":11839,\"name\":\"九游账号\",\"sort\":0,\"children\":[]},{\"id\":11846,\"parentFilterConfId\":11839,\"name\":\"应用宝服\",\"sort\":0,\"children\":[]},{\"id\":11847,\"parentFilterConfId\":11839,\"name\":\"B站服\",\"sort\":0,\"children\":[]},{\"id\":11848,\"parentFilterConfId\":11839,\"name\":\"小米服\",\"sort\":0,\"children\":[]},{\"id\":11849,\"parentFilterConfId\":11839,\"name\":\"华为安卓\",\"sort\":0,\"children\":[]},{\"id\":11850,\"parentFilterConfId\":11839,\"name\":\"VIVO安卓\",\"sort\":0,\"children\":[]}]},{\"id\":11840,\"parentFilterConfId\":0,\"name\":\"苹果\",\"sort\":0,\"children\":[{\"id\":11851,\"parentFilterConfId\":11840,\"name\":\"手机账号\",\"sort\":0,\"children\":[]},{\"id\":11852,\"parentFilterConfId\":11840,\"name\":\"邮箱账号\",\"sort\":0,\"children\":[]},{\"id\":11853,\"parentFilterConfId\":11840,\"name\":\"苹果ID\",\"sort\":0,\"children\":[]},{\"id\":11854,\"parentFilterConfId\":11840,\"name\":\"网易苹果\",\"sort\":0,\"children\":[]}]}]\n";
            JSONArray jsonArray1 = JSONArray.parseArray(qufus);
            for(Object o : jsonArray1){
                if(goodsInfoAndAttrValueDto.getSystemName().replace("IOS","苹果").equals(JSONObject.parseObject(o.toString()).getString("name"))){
                    String children = JSONObject.parseObject(o.toString()).getString("children");
                    JSONArray jsonArray2 = JSONArray.parseArray(children);
                    for(Object p : jsonArray2){
                        if(JSONObject.parseObject(p.toString()).getString("name").contains(goodsInfoAndAttrValueDto.getCarrierName())||JSONObject.parseObject(p.toString()).getString("name").contains(goodsInfoAndAttrValueDto.getGroupName())){
                            duoxuanmap.put("ids",JSONObject.parseObject(p.toString()).getString("id"));
                            duoxuanmap.put("names",JSONObject.parseObject(p.toString()).getString("name"));
                        }
                    }
                }
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间")){
            if(goodsInfoAndAttrValueDto.getGroupName().equals("网易")) {
                duoxuanmap.put("ids","18299");
                duoxuanmap.put("names","网易");
            }else {
                duoxuanmap.put("ids","18300");
                duoxuanmap.put("names","steam");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("部落冲突")){
            if(goodsInfoAndAttrValueDto.getSystemName().contains("国际服")) {
                duoxuanmap.put("ids","44475");
                duoxuanmap.put("names","微信");
            }else {
                duoxuanmap.put("ids","44476");
                duoxuanmap.put("names","QQ");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("崩坏:星穹铁道")){
            duoxuanmap.put("ids","1350");
            duoxuanmap.put("names","官服（星穹列车）");
            upperConf.put("youxiqufu", duoxuanmap);
            upperConf.put("shangpinmiaoshu", goodsInfoAndAttrValueDto.getDes());
            upperConf.put("shangpinfengmiantu", goodsInfoAndAttrValueDto.getTitleImg());
            //upperConf.put("shangpinxiangqingtu", goodsInfoImgList.stream().map(info -> info.getImgUrl()).collect(Collectors.toList()).stream().collect(Collectors.joining(",")));
            upperConf.put("shangpinliangdian", goodsInfoAndAttrValueDto.getTitle());
            duoxuanmap = new TreeMap<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF8())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF8()));
                if(gameAttribute1.getFieldName().equals("未绑定邮箱")){
                    duoxuanmap.put("ids",1352);
                    duoxuanmap.put("names","邮箱未绑定");
                }else if(gameAttribute1.getFieldName().equals("未实名邮箱")){
                    duoxuanmap.put("ids",1353);
                    duoxuanmap.put("names","邮箱未实名出售");
                }else if(gameAttribute1.getFieldName().equals("已实名邮箱")){
                    duoxuanmap.put("ids",1354);
                    duoxuanmap.put("names","邮箱实名出售");
                }else {
                    duoxuanmap.put("ids",1355);
                    duoxuanmap.put("names","邮箱不出售");
                }
            }else {
                duoxuanmap.put("ids",1352);
                duoxuanmap.put("names","邮箱未绑定");
            }
            upperConf.put("youxiangchushou", duoxuanmap);
            duoxuanmap = new TreeMap<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
                String string = "[{\"id\":1356,\"parentFilterConfId\":0,\"name\":\"男主\",\"sort\":0,\"children\":[]},{\"id\":1357,\"parentFilterConfId\":0,\"name\":\"女主\",\"sort\":0,\"children\":[]}]\n";
                JSONArray jsonArray1 = JSONArray.parseArray(string);
                for(Object o : jsonArray1){
                    if(JSONObject.parseObject(o.toString()).getString("name").equals(gameAttribute1.getFieldName())){
                        duoxuanmap.put("ids",JSONObject.parseObject(o.toString()).getString("id"));
                        duoxuanmap.put("names",JSONObject.parseObject(o.toString()).getString("name"));
                    }
                }
            }else {
                duoxuanmap.put("ids",1356);
                duoxuanmap.put("names","男主");
            }
            upperConf.put("zhujiaoxingbie", duoxuanmap);
            duoxuanmap = new TreeMap<>();
            duoxuanmap.put("ids",1358);
            duoxuanmap.put("names","是");
            upperConf.put("bangdingtap", duoxuanmap);
            duoxuanmap = new TreeMap<>();
            duoxuanmap.put("ids",1360);
            duoxuanmap.put("names","是");
            upperConf.put("bangdingpsn", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("三国杀")){
            duoxuanmap.put("ids","13254");
            duoxuanmap.put("names","移动3.0区");
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("金铲铲之战")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","13079");
                duoxuanmap.put("names","苹果微信");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","13077");
                duoxuanmap.put("names","安卓微信");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","13078");
                duoxuanmap.put("names","苹果QQ");
            }else {
                duoxuanmap.put("ids","13076");
                duoxuanmap.put("names","安卓QQ");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("逆水寒")){
            String string = "[{\"id\":10517,\"parentFilterConfId\":0,\"name\":\"逐中原\",\"sort\":0,\"children\":[{\"id\":10529,\"parentFilterConfId\":10517,\"name\":\"东京梦华\",\"sort\":0,\"children\":[]},{\"id\":10530,\"parentFilterConfId\":10517,\"name\":\"挑灯看剑\",\"sort\":0,\"children\":[]},{\"id\":10531,\"parentFilterConfId\":10517,\"name\":\"九天揽月\",\"sort\":0,\"children\":[]},{\"id\":10532,\"parentFilterConfId\":10517,\"name\":\"铁马秋风\",\"sort\":0,\"children\":[]},{\"id\":10533,\"parentFilterConfId\":10517,\"name\":\"应看千秋\",\"sort\":0,\"children\":[]}]},{\"id\":10518,\"parentFilterConfId\":0,\"name\":\"忆江南\",\"sort\":0,\"children\":[{\"id\":10534,\"parentFilterConfId\":10518,\"name\":\"烟雨江南\",\"sort\":0,\"children\":[]},{\"id\":10535,\"parentFilterConfId\":10518,\"name\":\"西子湖畔\",\"sort\":0,\"children\":[]},{\"id\":10536,\"parentFilterConfId\":10518,\"name\":\"姑苏绮罗\",\"sort\":0,\"children\":[]},{\"id\":10537,\"parentFilterConfId\":10518,\"name\":\"魔都风云\",\"sort\":0,\"children\":[]},{\"id\":10538,\"parentFilterConfId\":10518,\"name\":\"碧海问舟\",\"sort\":0,\"children\":[]}]},{\"id\":10519,\"parentFilterConfId\":0,\"name\":\"将进酒\",\"sort\":0,\"children\":[{\"id\":10539,\"parentFilterConfId\":10519,\"name\":\"群龙之首\",\"sort\":0,\"children\":[]},{\"id\":10540,\"parentFilterConfId\":10519,\"name\":\"天下无双\",\"sort\":0,\"children\":[]},{\"id\":10541,\"parentFilterConfId\":10519,\"name\":\"问鼎江湖\",\"sort\":0,\"children\":[]},{\"id\":10542,\"parentFilterConfId\":10519,\"name\":\"武林萌主\",\"sort\":0,\"children\":[]},{\"id\":10543,\"parentFilterConfId\":10519,\"name\":\"神龙九现\",\"sort\":0,\"children\":[]}]},{\"id\":10520,\"parentFilterConfId\":0,\"name\":\"踏北尘\",\"sort\":0,\"children\":[{\"id\":10544,\"parentFilterConfId\":10520,\"name\":\"紫禁之巅\",\"sort\":0,\"children\":[]},{\"id\":10545,\"parentFilterConfId\":10520,\"name\":\"武林天骄\",\"sort\":0,\"children\":[]},{\"id\":10546,\"parentFilterConfId\":10520,\"name\":\"瑶光听雪\",\"sort\":0,\"children\":[]},{\"id\":10547,\"parentFilterConfId\":10520,\"name\":\"帝都风云\",\"sort\":0,\"children\":[]},{\"id\":10548,\"parentFilterConfId\":10520,\"name\":\"云川雪青\",\"sort\":0,\"children\":[]}]},{\"id\":10521,\"parentFilterConfId\":0,\"name\":\"如梦令\",\"sort\":0,\"children\":[{\"id\":10549,\"parentFilterConfId\":10521,\"name\":\"江湖一梦\",\"sort\":0,\"children\":[]},{\"id\":10550,\"parentFilterConfId\":10521,\"name\":\"刀剑如梦\",\"sort\":0,\"children\":[]},{\"id\":10551,\"parentFilterConfId\":10521,\"name\":\"浮生若梦\",\"sort\":0,\"children\":[]},{\"id\":10552,\"parentFilterConfId\":10521,\"name\":\"仲夏绮梦\",\"sort\":0,\"children\":[]},{\"id\":10553,\"parentFilterConfId\":10521,\"name\":\"游园惊梦\",\"sort\":0,\"children\":[]}]},{\"id\":10522,\"parentFilterConfId\":0,\"name\":\"蝶恋花\",\"sort\":0,\"children\":[{\"id\":10554,\"parentFilterConfId\":10522,\"name\":\"宿命相逢\",\"sort\":0,\"children\":[]},{\"id\":10555,\"parentFilterConfId\":10522,\"name\":\"缘定三生\",\"sort\":0,\"children\":[]},{\"id\":10556,\"parentFilterConfId\":10522,\"name\":\"明月天涯\",\"sort\":0,\"children\":[]},{\"id\":10557,\"parentFilterConfId\":10522,\"name\":\"惊鸿照影\",\"sort\":0,\"children\":[]},{\"id\":10558,\"parentFilterConfId\":10522,\"name\":\"踏月留香\",\"sort\":0,\"children\":[]}]},{\"id\":10523,\"parentFilterConfId\":0,\"name\":\"决南岭\",\"sort\":0,\"children\":[{\"id\":10559,\"parentFilterConfId\":10523,\"name\":\"江山如画\",\"sort\":0,\"children\":[]},{\"id\":10560,\"parentFilterConfId\":10523,\"name\":\"一蓑烟雨\",\"sort\":0,\"children\":[]},{\"id\":10561,\"parentFilterConfId\":10523,\"name\":\"两广豪杰\",\"sort\":0,\"children\":[]},{\"id\":10562,\"parentFilterConfId\":10523,\"name\":\"沧海月明\",\"sort\":0,\"children\":[]},{\"id\":10563,\"parentFilterConfId\":10523,\"name\":\"君心如月\",\"sort\":0,\"children\":[]}]},{\"id\":10524,\"parentFilterConfId\":0,\"name\":\"逍遥游\",\"sort\":0,\"children\":[{\"id\":10564,\"parentFilterConfId\":10524,\"name\":\"千古风流\",\"sort\":0,\"children\":[]},{\"id\":10565,\"parentFilterConfId\":10524,\"name\":\"扶摇万里\",\"sort\":0,\"children\":[]},{\"id\":10566,\"parentFilterConfId\":10524,\"name\":\"飞花逐月\",\"sort\":0,\"children\":[]},{\"id\":10567,\"parentFilterConfId\":10524,\"name\":\"剑胆琴心\",\"sort\":0,\"children\":[]},{\"id\":10568,\"parentFilterConfId\":10524,\"name\":\"白帝霜华\",\"sort\":0,\"children\":[]}]},{\"id\":10525,\"parentFilterConfId\":0,\"name\":\"定风波\",\"sort\":0,\"children\":[{\"id\":10569,\"parentFilterConfId\":10525,\"name\":\"千里婵娟\",\"sort\":0,\"children\":[]},{\"id\":10570,\"parentFilterConfId\":10525,\"name\":\"翩若惊鸿\",\"sort\":0,\"children\":[]},{\"id\":10571,\"parentFilterConfId\":10525,\"name\":\"金风玉露\",\"sort\":0,\"children\":[]},{\"id\":10572,\"parentFilterConfId\":10525,\"name\":\"佳期如梦\",\"sort\":0,\"children\":[]},{\"id\":10573,\"parentFilterConfId\":10525,\"name\":\"雪泥鸿爪\",\"sort\":0,\"children\":[]}]},{\"id\":10526,\"parentFilterConfId\":0,\"name\":\"望海潮\",\"sort\":0,\"children\":[{\"id\":10574,\"parentFilterConfId\":10526,\"name\":\"日月同辉\",\"sort\":0,\"children\":[]},{\"id\":10575,\"parentFilterConfId\":10526,\"name\":\"九州风雷\",\"sort\":0,\"children\":[]},{\"id\":10576,\"parentFilterConfId\":10526,\"name\":\"满堂花醉\",\"sort\":0,\"children\":[]},{\"id\":10577,\"parentFilterConfId\":10526,\"name\":\"凭栏听雨\",\"sort\":0,\"children\":[]},{\"id\":10578,\"parentFilterConfId\":10526,\"name\":\"白夜拂雪\",\"sort\":0,\"children\":[]}]},{\"id\":10527,\"parentFilterConfId\":0,\"name\":\"凌西川\",\"sort\":0,\"children\":[{\"id\":10579,\"parentFilterConfId\":10527,\"name\":\"天府之国\",\"sort\":0,\"children\":[]},{\"id\":10580,\"parentFilterConfId\":10527,\"name\":\"天外飞仙\",\"sort\":0,\"children\":[]},{\"id\":10581,\"parentFilterConfId\":10527,\"name\":\"玲珑相思\",\"sort\":0,\"children\":[]},{\"id\":10582,\"parentFilterConfId\":10527,\"name\":\"绝代风华\",\"sort\":0,\"children\":[]},{\"id\":10583,\"parentFilterConfId\":10527,\"name\":\"燕字归时\",\"sort\":0,\"children\":[]}]},{\"id\":10528,\"parentFilterConfId\":0,\"name\":\"渠道服\",\"sort\":0,\"children\":[{\"id\":10584,\"parentFilterConfId\":10528,\"name\":\"春风十里\",\"sort\":0,\"children\":[]},{\"id\":10585,\"parentFilterConfId\":10528,\"name\":\"谁主沉浮\",\"sort\":0,\"children\":[]},{\"id\":10586,\"parentFilterConfId\":10528,\"name\":\"湖光水镜\",\"sort\":0,\"children\":[]},{\"id\":10587,\"parentFilterConfId\":10528,\"name\":\"风云再起\",\"sort\":0,\"children\":[]},{\"id\":10588,\"parentFilterConfId\":10528,\"name\":\"剑指天下\",\"sort\":0,\"children\":[]},{\"id\":10589,\"parentFilterConfId\":10528,\"name\":\"雷霆万钧\",\"sort\":0,\"children\":[]},{\"id\":10590,\"parentFilterConfId\":10528,\"name\":\"高山流水\",\"sort\":0,\"children\":[]},{\"id\":10591,\"parentFilterConfId\":10528,\"name\":\"对酒狂歌\",\"sort\":0,\"children\":[]},{\"id\":10592,\"parentFilterConfId\":10528,\"name\":\"折梅煮酒\",\"sort\":0,\"children\":[]},{\"id\":10593,\"parentFilterConfId\":10528,\"name\":\"诗酒华章\",\"sort\":0,\"children\":[]},{\"id\":10594,\"parentFilterConfId\":10528,\"name\":\"云天自在\",\"sort\":0,\"children\":[]}]}]\n";
            JSONArray jsonArray1 = JSONArray.parseArray(string);
            for(Object o : jsonArray1){
                String children = JSONObject.parseObject(o.toString()).getString("children");
                JSONArray jsonArray2 = JSONArray.parseArray(children);
                for(Object p : jsonArray2){
                    if(JSONObject.parseObject(p.toString()).getString("name").equals(goodsInfoAndAttrValueDto.getServerName())){
                        duoxuanmap.put("ids",JSONObject.parseObject(p.toString()).getString("id"));
                        duoxuanmap.put("names",JSONObject.parseObject(p.toString()).getString("name"));
                    }
                }
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟(手游)")){
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("苹果微信")) {
                duoxuanmap.put("ids","18831");
                duoxuanmap.put("names","苹果(微信账号）");
            }else if(regional.equals("安卓微信")) {
                duoxuanmap.put("ids","18829");
                duoxuanmap.put("names","安卓(微信账号）");
            }else if(regional.equals("苹果QQ")) {
                duoxuanmap.put("ids","18830");
                duoxuanmap.put("names","苹果(QQ账号）");
            }else {
                duoxuanmap.put("ids","18828");
                duoxuanmap.put("names","安卓(QQ账号）");
            }
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("绝地求生")){
            duoxuanmap.put("ids","12154");
            duoxuanmap.put("names","全区全服");
            upperConf.put("youxiqufu", duoxuanmap);
        }
        if(goodsInfoAndAttrValueDto.getGameName().equals("瓦罗兰特")){
            duoxuanmap.put("ids","13711");
            duoxuanmap.put("names","全区全服");
            upperConf.put("youxiqufu", duoxuanmap);
        }
//        //区服
//        builderServer(goodsInfoAndAttrValueDto, params, interAttr.getServer());
        
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto, upperConf, interAttr.getRadioAttr());
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto, upperConf, interAttr.getCheckAttr());
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto, upperConf, interAttr.getInputAttr());
        
        
        
        if(type!=3) {
            params.put("goodsNum", 1);
            params.put("upperConf", JSONObject.toJSONString(upperConf));
//            BigDecimal bigDecimal = commonApi.addPrice(goodsInfoAndAttrValueDto.getPrice(), salePartner.getSeleep());
            params.put("price", goodsInfoAndAttrValueDto.getPrice());
            params.put("uid", "zyl-"+goodsInfoAndAttrValueDto.getId());
        }
        if(type==3) {
            params.put("status", "2");
        }else if(type==4) {
            params.put("status", "1");
        }
        String cover = MapUntils.getCover(params);
        cover = cover + "key="+salePartner.getSaleKey();
        System.out.println(cover);
        String sign = DigestUtils.md5Hex(cover).toUpperCase();
        params.put("sign",sign);
        return params;
    }
    @Autowired
    private CommonApi commonApi;
    public static void main(String[] args) {
//        String attr = getAttr(19);
//        System.out.println(attr);
    }

    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String radioAttr) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (!org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            /**
             * 1、先查询自定义中所有单选的字段
             * 2、再查该账号单选字段中的选项
             * 3、再去接口属性匹配表过滤
             */
            GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
            gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
            gameAttrTemplate.setIsEnable("0");
            gameAttrTemplate.setFieldType("radio");
            List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
            Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();


            List<JSONObject> defObjects = new ArrayList<>();
            defObjects.addAll(jsonObjects);
            for (JSONObject object : jsonObjects) {
                JSONObject att = new JSONObject();
                for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                    String aavName = attrTemplate.getAavName();
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (aavName.equals(name)) {
                            //一级属性
                            //注意 YdConfigId 对应的是 f字段对应的 id
                            if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                                String InterConfigId = object.getString("InterConfigId");
                                defObjects.remove(object);//如果匹配上，则去掉
                                String interRadioReqs1 = object.getString("interRadioReqs");
                                List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                                declaredField.setAccessible(true);
                                try {
                                    //获取选择的值 例如  实名中的可二次
                                    Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                    String oneValue = String.valueOf(o);
                                    List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> Objects.equals(j.getString("YdConfigId"), oneValue)).collect(Collectors.toList());

                                    if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        JSONObject jsonObject2 = twoAttr.get(0);
                                        String id = jsonObject2.getString("id");
                                        String names = jsonObject2.getString("name");
                                        att.put("ids", id);
                                        att.put("names", names);
                                        params.put(InterConfigId, att);
                                    }else {
                                        JSONObject jsonObject1 = jsonObjects2.get(0);
                                        String id = jsonObject1.getString("id");
                                        String names = jsonObject1.getString("name");
                                        att.put("ids", id);
                                        att.put("names", names);
                                        params.put(InterConfigId, att);
                                    }
                                } catch (Exception e) {
                                    throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                            }
                        }
                    }
                }
            }
            //开始匹配默认值
            for (JSONObject object : defObjects) {
                JSONObject att = new JSONObject();
                String id = object.getString("id");
                interRadioReqs = object.getString("interRadioReqs");
                jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
                for (JSONObject objects : jsonObjects) {
                    if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                        att.put("ids", objects.getString("id"));
                        att.put("names", objects.getString("name"));
                        params.put(id, att);
                    }
                }
            }
            //========================单选属性匹配结束=====================//
        }
    }

    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String inputAttr) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        for (JSONObject object : jsonObjects1) {
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                JSONObject att = new JSONObject();
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String aavNameInter = object.getString("interName");
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            if (Objects.nonNull(o)) {
                                String oneValue = String.valueOf(o);
                                params.put(interId, Integer.parseInt(oneValue));
                            }else {
                                params.put(interId, 1);
                            }
                        }
                    }
                }

            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            String id = object.getString("id");
            String defaultValue = object.getString("defaultValue");
            if (StringUtils.isNotEmpty(defaultValue)) {
                params.put(id,1);
            }
        }
    }
//    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String checkAttr) {
//        /**
//         * 1、先查询自定义中所有多选的字段
//         * 2、再查该账号单选字段中的选项
//         * 3、再去接口属性匹配表过滤
//         */
//        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
//        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
//        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
//        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
//        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
//            throw new GlobalException("接口多选属性暂未配置");
//        }
//
//        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
//        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
//        gameAttrTemplate.setIsEnable("0");
//        List<String> types = new ArrayList<>();
//        types.add("checkbox");
//        types.add("boxradio");
//        gameAttrTemplate.setFieldTypes(types);
//        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
//
//        for (JSONObject object : checkJsonList) {
//            Map duoxuanmap = new HashMap<>();
//
//            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {
//
//                String aavName = attrTemplate.getAavName();
//                for (Field declaredField : declaredFields) {
//                    String name = declaredField.getName();
//                    if (aavName.equals(name)) {
//                        declaredField.setAccessible(true);
//
////                        List<String> list2 = new ArrayList<>();
////                        for (String s : split2) {
////                            s = s.replace(" ", "");
////                            list2.add(s);
////                        }
//                        Object o = null;
//                        try {
//                            o = declaredField.get(goodsInfoAndAttrValueDto);
//                        } catch (IllegalAccessException e) {
//                            throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
//                        }
//                        String oneValue = String.valueOf(o);
//                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
//                        //开始匹配二级属性
//                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
//                        /**
//                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
//                         */
//                        String ids = "";
//                        String names = "";
//                        for (JSONObject jsonObject1 : jsonObjects2) {
//                            String[] split1 = oneValue.split(",");
//                            String ydConfigId1 = jsonObject1.getString("YdConfigId");
//                            if(StringUtils.isNotEmpty(ydConfigId1)){
//                                ydConfigId1 = ydConfigId1.replace(" ","");
//                            }
//                            for (String s : split1) {
//                                if (Objects.equals(s, ydConfigId1)) {
//                                    String InterConfigId2 = jsonObject1.getString("InterConfigId");
//                                    ids+=","+InterConfigId2;
//                                    names+=","+jsonObject1.getString("name");
//                                }
//                            }
//                        }
//                        if (StringUtils.isNotEmpty(ids)) {
//                            duoxuanmap.put("ids",ids.substring(1));
//                            duoxuanmap.put("names",names.substring(1));
//                            params.put(object.getString("id"), duoxuanmap);
//                        }else {
//                            JSONObject jsonObject1 = jsonObjects2.get(0);
//                            duoxuanmap.put("ids",jsonObject1.getString("id"));
//                            duoxuanmap.put("names",jsonObject1.getString("name"));
//                            params.put(object.getString("id"), duoxuanmap);
//                        }
//                    }
//                }
//            }
//        }
//    }
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String checkAttr) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        //========================开始匹配多选属性=====================//
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        for (JSONObject object : checkJsonList) {
            Map duoxuanmap = new HashMap<>();
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);

                        String ydConfigIdLeveOne = object.getString("YdConfigId");
                        if (StringUtils.isNotEmpty(ydConfigIdLeveOne)) {

                            String[] split2 = ydConfigIdLeveOne.split(",");
                            List<String> list2 = new ArrayList<>();
                            for (String s : split2) {
                                s = s.replace(" ", "");
                                list2.add(s);
                            }
                            if (list2.contains(attrTemplate.getId() + "")) {
                                Object o = null;
                                try {
                                    o = declaredField.get(goodsInfoAndAttrValueDto);
                                } catch (IllegalAccessException e) {
                                    throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                                String oneValue = String.valueOf(o);
                                //一级属性
                                String ydConfigId = object.getString("YdConfigId");
                                String InterConfigName = object.getString("InterConfigName");
                                String InterConfigId = object.getString("InterConfigId");
                                if (StringUtils.isNotEmpty(ydConfigId)) {
                                    String[] split = ydConfigId.split(",");
                                    //一级属性已经匹配，开始匹配二级属性
                                    if (Arrays.asList(split).contains(attrTemplate.getId() + "")) {
                                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
//                                        String interCheckBoxReqsStr = object.getString("interServerRes");
                                        //开始匹配二级属性
                                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                                        /**
                                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                                         */
                                        String ids = "";
                                        String names = "";
                                        for (JSONObject jsonObject1 : jsonObjects2) {
                                            if (StringUtils.isNotEmpty(oneValue)) {
                                                String[] split1 = oneValue.split(",");
                                                String ydConfigId1 = jsonObject1.getString("YdConfigId");
                                                for (String s : split1) {
                                                    if (Objects.equals(s, ydConfigId1)) {
                                                        String InterConfigId2 = jsonObject1.getString("InterConfigId");
                                                        ids += "," + InterConfigId2;
                                                        names += "," + jsonObject1.getString("name");
                                                    }
                                                }
                                            }
                                        }
                                        if (StringUtils.isNotEmpty(ids)) {
                                            duoxuanmap.put("ids", ids.substring(1));
                                            duoxuanmap.put("names", names.substring(1));
                                            params.put(object.getString("id"), duoxuanmap);
                                        } else {
                                            JSONObject jsonObject1 = jsonObjects2.get(0);
                                            duoxuanmap.put("ids", jsonObject1.getString("id"));
                                            duoxuanmap.put("names", jsonObject1.getString("name"));
                                            params.put(object.getString("id"), duoxuanmap);
                                        }
                                    }
                                } else {
                                    throw new GlobalException("属性参数错误，请匹配后重新配置");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
